﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Master/Admin.Master" AutoEventWireup="true"
    CodeBehind="RoomPriceList.aspx.cs" Inherits="Besture.UI.RoomPriceList" %>  
<%@ Register Src="~/Admin/Control/HotelUserControl.ascx" TagPrefix="cms" TagName="HotelUserControl" %>
<%@ Register Src="~/Admin/Control/BatchModifyLowPriceControl.ascx" TagPrefix="cms" TagName="BatchModifyLowPriceControl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
    <link href="../Themes/Room/css/Common.css" rel="stylesheet" />
    <link href="../Themes/Room/css/style.css" rel="stylesheet" />
    <link href="../Themes/Css/normalize.css" rel="stylesheet" />
    <link href="../Themes/Css/common.css" rel="stylesheet" />

    <style>
        .pop-box {height: 188px !important;width: 450px !important;}
        .btn-cancel { padding: 0px  !important;}
    </style>
    <script type="text/javascript"> 
        //日历的展开收缩操作
        function toggleType(obj, isTitle) {
            var roomTypeContainer = $(obj).parent().parent().find("div.room-price-bd");
            if (roomTypeContainer.is(":hidden")) {
                if (!isTitle) {
                    $(obj).addClass("btn-unfold");
                    $(obj).removeClass("btn-fold");
                    $(obj).find("label").html("展开 ");
                }
                else {
                    $(obj).next("a").find("label").html("收起 ");
                }
                roomTypeContainer.show();
            }
            else {
                if (!isTitle) {
                    $(obj).addClass("btn-fold");
                    $(obj).removeClass("btn-unfold");
                    $(obj).find("label").html("收起 ");
                }
                else {
                    $(obj).next("a").find("label").html("展开 ");
                }
                roomTypeContainer.hide();
            }
        } 

        function GetQuery() {

            //上一月份
            $('#prevMonth').click(function () {
                $("#<%=hidColendarMonth.ClientID%>").val(1);
                $("#<%=btnSeach.ClientID%>").click();
            });


            //下一月份
            $('#benMonth').click(function () {
                $("#<%=hidColendarMonth.ClientID%>").val(0);
                $("#<%=btnSeach.ClientID%>").click();
            });

            //下一月份
            $('#nextMonth').click(function () {
                $("#<%=hidColendarMonth.ClientID%>").val(2);
                $("#<%=btnSeach.ClientID%>").click();
            });

            /** 点击【查询】按钮后 触发事件 **/
            $(".btn.btn-query").click(function () {
                //获取选中房型id
                var vRoomId = $("#ctl00_Content_HotelUserControl_ddlRoom").val();
                var vHotels = $("#ctl00_Content_HotelUserControl_ddlHotels").val();
                if (vHotels.length < 1) {
                    alert("请选择酒店");
                    return;
                }
                if (vRoomId > 0) {
                    $("#<%=hidID.ClientID%>").val("1|" + vRoomId);
                } else {
                    //获取选中酒店id ;0表示显示酒店全部房型 反之1某一个房型
                    $("#<%=hidID.ClientID%>").val("0|" + vHotels);
                }
                $("#<%=btnSeach.ClientID%>").click();
            });
        }

        function GetInLoadCalendar() {

            $(".calendar.clearfix.room-price-bd").each(function () {
                var _this = $(this);
                var rID = _this.find(".yearMonth i").text(); //房型id 

                var cal = new BookingCalendar({
                    container: _this,
                    onSelected: function (selection) {
                       // $(_this).find("td").click(function() {
                            var rLowPrice = $(_this).find("td").attr("tabindex");
                            var pTitle = selection.toString();
                            var pText = pTitle.length < 11 ? pTitle : pTitle.substring(0, 10) + "...";
                            //弹窗
                            $("#<%=txt_box_LowPrice.ClientID%>").val(rLowPrice);
                            $(".mask").height($(".editPage").height()).show();
                            $(".pop-box").show().children("a").attr("title", rID + "|" + pTitle).text(pText);
                            $(".pop-btn").removeData("calender").data("calender", cal);
                       // });
                    }
                });
            });
        }


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>  
    <input type="hidden" id="hidBreakfast" value="0" runat="server" />
    <input type="hidden" id="hidRoom" value="" runat="server" />
    <input type="hidden" id="hidID" value="" runat="server" /> 
    <input type="hidden" id="hidColendarMonth" value="0" runat="server" /> 
    <%--hidColendarMonth : 0表示当前月份; 1表示前月份; 2表示前月份--%>
    <div class="editPage">
        <ul class="tab">
            <li class="on" onclick="setTab(this,0)"><a href="javascript:void(0)" title="房型底价维护">房型底价维护</a></li>
            <li onclick="setTab(this,1)"><a href="javascript:void(0)" title="批量修改底价">批量修改底价</a></li>
        </ul>
        <div class="tab-ct-wrap">
            <div class="tab1">
                <cms:HotelUserControl runat="server" ID="HotelUserControl" />
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>   
                        <span style="display: none">
                            <asp:Button ID="btnSeach" runat="server" Text="查询" UseSubmitBehavior="false" OnClick="BtnSeachClick" />
                        </span>
                        <%--20150507 lyg start 日历--%>
                        <div id="calendarWrap" runat="server" class="calendar-wrap">
                            <!--说明-->
                            <div class="sec-room-guide clearfix">
                                <ul class="ui-guide-info clearfix">
                                    <li><i class="room-color room-orange"></i>预付卖价-底价</li>
                                    <li><i class="room-icon icon-breakfast"></i>早餐份数</li>
                                </ul>
                                <ul class="ui-guide-info clearfix" style="float: right;">
                                    <li><a href="javascript:void(0);" id="prevMonth" class="ui-link">&lt; 前一月</a>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <a href="javascript:void(0);" id="benMonth" class="ui-link"> 本月</a>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                         <a href="javascript:void(0);" id="nextMonth" class="ui-link">后一月&gt;</a>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        当前显示&nbsp;&nbsp;<input type="text"  runat="server" disabled="disabled" style="width:20px" id="txtMonth" />&nbsp;&nbsp;月份
                                    </li>
                                </ul>
                            </div>
                            <!--日历-->
                            <asp:Repeater ID="rpRoom" runat="server">
                                <ItemTemplate>
                                    <div class="sec-room-price">
                                        <div class="room-price-hd">
                                            <h3 class="ui-room-title" onclick="toggleType(this, true)"><span><%#Eval("RoomName") %></span></h3>
                                            <a href="javascript:void(0);" onclick="toggleType(this)" class="btn-fold">
                                                <label>收起 </label>
                                                <i class="icon-arrows"></i></a>
                                        </div>
                                        <div class="calendar clearfix  room-price-bd">
                                            <div class="yearMonth">
                                                <%= IDataNow.Year%>年<%=IDataNow.Month %>月
                                                <i style="display: none"><%#Eval("ID") %></i>
                                                <span style="display: none"><%#Eval("LowPrice") %></span>
                                            </div>
                                            <table>
                                                <thead>
                                                    <tr>
                                                        <th>周日</th>
                                                        <th>周一</th>
                                                        <th>周二</th>
                                                        <th>周三</th>
                                                        <th>周四</th>
                                                        <th>周五</th>
                                                        <th>周六</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                     <%# GetCalendarData(Convert.ToInt32(Eval("ID"))) %>
                                                <tbody>
                                            </table>
                                        </div>
                                    </div>
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                        <%--20150507 lyg end 日历--%>
                        <!--遮罩-->
                        <div class="mask" style="width: 1122px; height: auto"></div>
                    </ContentTemplate>
                </asp:UpdatePanel>

            </div>
            <div class="tab1" style="display: none;">
                <cms:BatchModifyLowPriceControl runat="server" ID="BatchModifyLowPriceControl" />
            </div>
        </div>
        <!--弹窗-->
        <div class="pop-box">
            <a href="javascript:void(0);" title=""></a>
            <div>
                <span>早餐情况：</span>
                <img src="/Admin/Themes/Images/dispensable.png" align="absMiddle">
                <asp:DropDownList ID="ddl_box_Breakfast" runat="server"></asp:DropDownList>
            </div>    
            <div>
                <span>预付底价：</span>
                <img src="/Admin/Themes/Images/indispensable.gif" align="absMiddle">
                <input type="text" class="required number" id="txt_box_LowPrice" runat="server" />
            </div> 
            <div>
                <asp:Button ID="btnSavePrice" class="pop-btn btn-ok" runat="server" Text="确定" OnClick="btnSavePrice_Click" />
                <a href="javascript:void(0);" class="pop-btn btn-cancel">取消</a>
            </div>
        </div>
    </div>     
    <script type="text/javascript">

        /** 日历效果 start lyg **/
        var BookingCalendar = function (data) {
            var onSelected;
            var selection = [];
            var calendar = $("#calendar");
            var selectStart = false;
            var ctrl = false;

            if (data) {
                if (data.onSelected)
                    onSelected = data.onSelected;
                if (data.container)
                    calendar = $(data.container); //$("#calendar");
            }

            if (!calendar.length) return;

            $("body,html").keydown(function (e) {
                if (e.keyCode == 17) {
                    ctrl = true;
                }

            }).keyup(function (e) {
                if (e.keyCode == 17) {
                    ctrl = false;
                    //松开ctrl时，判断是否有选中并回调
                    if (selection != null && selection.length > 0 && onSelected)
                        onSelected(selection);
                }
            });

            calendar.on("mousedown", "td:not('.disabled')", function (e) {
                if (e.which == 1) {
                    var _day = $(this);
                    preSelectStart(_day);
                }
            }).on("mouseover", "td:not('.disabled')", function () {
                var _day = $(this);
                preSelect(_day);
            }).on("mouseup", "td:not('.disabled')", function (e) {
                selectEnd();

                if (!ctrl && selection != null && selection.length > 0 && onSelected) {
                    onSelected(selection);
                }
            });

            $("html,body").mouseup(function (e) {
                if (e.which == 1) {
                    if (!selectStart) return;
                    selectEnd();
                    if (!ctrl) {
                        if (onSelected) onSelected(selection);
                    }
                }
            });

            function preSelectStart(jObj) {
                var childrenDiv = jObj.children();
                if (ctrl && (childrenDiv.is(".pre-select") || childrenDiv.is(".selected"))) {
                    clear(jObj);
                } else {
                    selectStart = true;
                    preSelect(jObj);
                }
            }

            function preSelect(_jCurrentDate) {
                if (selectStart) {
                    _jCurrentDate.children().addClass("pre-select");
                }
            }

            function selectEnd() {
                $(".pre-select", calendar).each(function () {
                    var _this = $(this);
                    select(_this.parent());
                });
                selectStart = false;
            }

            function select(obj) {
                var date = getDateAttr(obj);
                var index = $.inArray(date, selection);
                if (index == -1) {
                    selection.push(date);
                }

                obj.children().addClass("selected").removeClass("pre-select");
            }

            this.clearAll = function () {
                selection = [];
                $("td", calendar).children().removeClass("selected").removeClass("pre-select");
            }

            function clear(jObj) {
                var date = getDateAttr(jObj);
                var index = $.inArray(date, selection);
                if (index > -1) selection.splice(index, 1);

                jObj.children().removeClass("selected").removeClass("pre-select");
            }

            function getDate(obj) {
                return new Date(getDateAttr(obj));
            }

            function getDateAttr(obj) {
                return $(obj).attr("date");
            }
        }
        /** 日历效果 end lyg **/

        $(function () {

            //弹出框 取消 事件 
            $(".pop-btn.btn-cancel").click(function () {
                var cal = $(this).data("calender");
                cal.clearAll();
                $(".pop-box").hide();
                $(".mask").hide();
            });

            //弹出框 确定 事件
            $(".pop-btn.btn-ok").click(function () {
                //获取 房型id 和 日期
                var vhotels = $(this).parents(".pop-box").find("a").attr("title");
                $("#<%=hidRoom.ClientID%>").val(vhotels);
                $("#<%=hidBreakfast.ClientID%>").val($("#<%=ddl_box_Breakfast.ClientID%>").val());
                var cal = $(this).data("calender");
                cal.clearAll();
            });
            GetQuery();//初始化
            GetInLoadCalendar();//日历 each  初始化  
        });
    </script>
</asp:Content>
